/*******************************************
 *                                         *
 *******************************************/

#include "Tiles.h"

Tiles::Tiles (void)
{
	for (int i = 0; i < 5; i++)
		this->TetrisTiles[i] = NULL;
}

Tiles::Tiles (LPDIRECT3DDEVICE9 DrawDevice)
{
	for (int i = 0; i < 5; i++)
		this->TetrisTiles[i] = NULL;
	this->Init(DrawDevice);
}

Tiles::~Tiles (void)
{
	for (int i = 0; i < 5; i++)
	{
		if (this->TetrisTiles[i])
			delete this->TetrisTiles[i];
	}
}

BOOL Tiles::Init (LPDIRECT3DDEVICE9 DrawDevice)
{
	BOOL Success = TRUE;

	for (int i = 0; i < 5; i++)
	{
		if (!(this->TetrisTiles[i] = new Sprite(DrawDevice, 16.0f, 16.0f, 0.5f)))
			Success = FALSE;
	}
	if (Success)
		LoadTiles();

	return Success;
}

LPSPRITE Tiles::GetTile (int Tile)
{
	if ((Tile >= 0) && (Tile <= 4))
		return this->TetrisTiles[Tile];
	return NULL;
}

void Tiles::LoadTiles (void)
{
	this->TetrisTiles[RED]->LoadTexture(L"RedTile.png");
	this->TetrisTiles[GREEN]->LoadTexture(L"GreenTile.png");
	this->TetrisTiles[BLUE]->LoadTexture(L"BlueTile.png");
	this->TetrisTiles[YELLOW]->LoadTexture(L"YellowTile.png");
	this->TetrisTiles[PURPLE]->LoadTexture(L"PurpleTile.png");
}